<?php

@session_start();

require 'conf.php';

function getevents($sessiontoken, $start, $end)
{ 
    global $MW_host;
    $fields = array('USR_EVENT_RANGE' => '',
                    'SESSION' => $sessiontoken,
                    'START' => $start,
                    'END' => $end);

    $fields = http_build_query($fields);

    $h = curl_init($MW_host); 
    curl_setopt($h, CURLOPT_POST, 1);
    curl_setopt($h, CURLOPT_POSTFIELDS, $fields); 
    curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($h, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($fields))); 

    $res = curl_exec($h);

    if(!mb_check_encoding($res, 'UTF-8'))
        $res = utf8_encode($res);
    $data = json_decode($res);
    return $data;
}

$events = getevents($_SESSION['sessiontoken'], $_GET['start'], $_GET['end']);
$arr = array();
foreach($events as $e) {
    $arr[] = array('title' => $e->e_desc, 'start' => $e->start / 1000 , 'stop' => $e->stop / 1000, 'end' => $e->stop / 1000, 'allDay' => false, 'etype' => $e->etype, 'eid' => $e->eid, 'name' => $e->name, 'pubshare' => $e->pubshare );
}

print json_encode($arr);

?>
